<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="true" %>

<script>
$(document).ready(function() {
	$("#all_checkbox").click(function() {
		var check = $("#all_checkbox").is(":checked"); 

	    $("input[name='chkSign']:checkbox").each(function(){ 
	    	$(this).prop("checked", check);
	    }); 
	});
});

function qnaWrite(prdcd) {
	location.href="/vhmall/qna_write.vh?prdcd=" + prdcd;
}

/////////////////////////////////////////////////////////////////////////////// 
//  나의 찜 선택삭제                                                   //
/////////////////////////////////////////////////////////////////////////////// 
function deleteWishUser(key) {
  var cartList = getWishList();
  cartList = eval('(' + cartList + ')');
  var selindex;
  $.each(cartList, function(index, value){
    if(key==cartList[index].a){
      selindex = index;
    }
   
  });
  cartList.splice(selindex,1);
  
  setCartList('updateWish',cartList);
  location.href="/vhmall/wishlist.vh";      
}

///////////////////////////////////////////////////////////////////////////////
//  선택된 상품만 (삭제)                                                  //
///////////////////////////////////////////////////////////////////////////////
function fnChkPrd(mode){
   var checkPrd = new Array();
   $('input:checkbox[name=chkSign]:checked').each(function(i){       
      checkPrd[i] = $(this).get(0).value;
   });
   //* 선택된상품삭제
   if(checkPrd<=0){
     alert("상품을 선택해주세요");
     return false;
   }
   
   deleteWish(checkPrd);
}

///////////////////////////////////////////////////////////////////////////////
//회원 주문하기                        	                                 //
///////////////////////////////////////////////////////////////////////////////
function fnOrderMember(flag,obj){
	var chkSign = $("input[name='chkSign']:checked");
	if( chkSign.length <= 0 ){
		alert("구매하실 상품을 선택하세요.");
		return false;
	}
    $.cookies.set('orderList','[]');  //초기화       
    var orderList = $.cookies.get('orderList');
     
   	//선택된것담기
 	var prdSap = new Array();
   	var i = 0;
 	$('input:checkbox[name=chkSign]:checked').each(function(i){       
 	 	prdSap[i] = $(this).get(0).value;
 	 	orderList.push( {a: prdSap[i].split("_")[0]+"_"+prdSap[i].split("_")[1], b: Number(1), c: Number(prdSap[i].split("_")[2]), d:(prdSap[i].split("_")[3])} );
 	 	i++;
 	});
 	
    setCartList('update2',orderList);  
    location.replace("/vhmall/order.vh");
}

///////////////////////////////////////////////////////////////////////////////
//  회원 장바구니로                         	                                 //
///////////////////////////////////////////////////////////////////////////////
function fnCartMember(flag,obj){
  var chkSign = $("input[name='chkSign']:checked");
  if( chkSign.length <= 0 ){
    alert("구매하실 상품을 선택하세요.");
    return false;
  }
  
  //선택된것담기
  var prdSap = new Array();
  $('input:checkbox[name=chkSign]:checked').each(function(i){       
     prdSap[i] = $(this).get(0).value;
  });
  //상품없이 주문할때
  if(prdSap.length<=0 && obj!="A"){
    alert("구매하실 상품을 선택하세요.");
    return false;
  }
  
  //장바구니
  var cartListTmp = getCartList();
  var cartList = '';
  if(cartListTmp == '0'){
    cartList = eval('(' + '[]' + ')');
  }else{
    cartList = eval('(' + cartListTmp + ')');
  }
  
  //체크선택
  for(var i=0;i<prdSap.length;i++){
      for(var j=0;j<cartList.length;j++){
          if((prdSap[i].split("_")[0]+"_"+prdSap[i].split("_")[1])!=cartList[j].a){
        	  cartList.push( {a: prdSap[i].split("_")[0]+"_"+prdSap[i].split("_")[1], b: Number(1), c: Number(prdSap[i].split("_")[2]), d:(prdSap[i].split("_")[3])} );
      	  }
      }
  }
  
  setCartList('update2',cartList);
  location.href="/vhmall/cart.vh";
}
</script>

<!-- 콘텐츠 영역 -->
    <div id="BodyWrap">
        <section>
            <h4 class="pag_title">나의 찜 목록</h4>
            <div id="ContentWrap4">
            	<div class="mar_b10">
                	<div class="inp_ckb">
                        <input type="checkbox" class="ckb" name="all_checkbox" id="all_checkbox">
                        <label for="all_checkbox">전체선택</label>
                    </div>
                </div>
                <ul class="showwindow_list3">
                	<c:forEach items="${requestScope.itemList }" var="items" varStatus="status">
	                	<li>
	                    	<div class="inp_ckwrap2">
	                        	<div class="inp_ckb2">
	                            	<input type="checkbox" class="ckb" name="chkSign" id="chkSign${status.index}" value="${items.PRDCD}_${items.SAPCD}_${items.SELPRC}_${items.CORPNO}" />
	                                <label for="all_checkbox">&nbsp;</label>
	                            </div>
	                        </div>
	                    	<a href="${contextPath}/vhmall/item_detail.vh?prdcd=${items.PRDCD}" class="thumb">
	                            <img src="http://www.vhmall.co.kr/inc/imgLoad.jsp?dirName=product/${items.CORPNO}/&fileName=${items.PRDIMG1_ENC}&thumb=Y&quality=100&size=230" alt="">
	                        </a>
	                        <div class="windowinfo_area">
	                            <a href="${contextPath}/vhmall/item_detail.vh?prdcd=${items.PRDCD}" class="title">
	                            	<span style="color:#e42526;font-weight:bold;">${items.PREPROMOTE}</span>
	                            	${items.PRDNM }
	                            	<span style="color:#666;">${items.ENDPROMOTE}</span></a>
	                            </a>
	                            <p class="price">
	                            	<c:if test="${items.CPNPRC!=null}">
		                                <span class="discount"><em>${items.SELPRC}</em>원</span>
		                                ${items.CPNPRC}원
	                                </c:if>
	                                <c:if test="${items.CPNPRC==null}">
	                                	${items.SELPRC}원
	                                </c:if>
	                            </p>
	                            <p class="btnposition_box">
	                                <a href="#" class="btn_inlistyle1 gradation_gray1" title="삭제하기" onclick="deleteWishUser('${items.PRDCD}_${items.SAPCD}');"  return false;>삭제하기</a>
	                                <a href="#" class="btn_inlistyle1 gradation_gray1 ftc_darkred" title="1:1문의" onclick="qnaWrite('${items.PRDCD}');">1:1문의</a>
	                            </p>
	                        </div>
	                    </li>
	                   </c:forEach>
                </ul>
                <div class="btnposition_itembuy">
                    <div class="btnwline3">
                        <a href="javascript:fnCartMember();" class="cart" title="장바구니 담기">장바구니 담기</a>
                        <a href="javascript:fnChkPrd('del');"" class="delete" title="삭제하기">삭제하기</a>
                        <a href="javascript:fnOrderMember();" title="주문하기">주문하기</a>
                    </div>
                </div>
            </div>
        </section>
        <!--// 콘텐츠 영역 -->